const express = require('express');
const router = express.Router();
const adminController = require('../controllers/admincontroller');
const authMiddleware = require('../middleware/authMiddleware');
const adminMiddleware = require('../middleware/adminMiddleware');

// 应用权限中间件
router.use(authMiddleware);
router.use(adminMiddleware);

/**
 * 管理员路由 - 仅管理员可访问
 * 路由前缀: /api/admin
 */

// 用户管理路由
router.get('/users', adminController.getNormalUsers);
router.get('/users/:id', adminController.getUserById);
router.delete('/users/:id', adminController.deleteUser);
router.put('/users/:id', adminController.updateUser);

// 商品管理路由
router.get('/products', adminController.getProducts);
router.put('/products/:id/status', adminController.updateProductStatus);
router.get('/products/categories', adminController.getAllCategories);
// 已删除无用的下架和上架路由，统一使用status路由

// 添加分类创建路由
router.post('/categories', adminController.createCategory);

// 交易管理路由
router.get('/transactions', adminController.getTransactions);
router.get('/transactions/:id', adminController.getTransactionDetail);

module.exports = router;